<?php

/**
 * uniBoard Settings groups list
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-15 17:35:38 +0000 (Wed, 15 Sep 2010) $
 * $Revision: 61 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_settings_list{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Draw page help
		$appCore -> output -> page_help = $appCore -> lang['acp_settings_groups_help'];
		
		// Resynch group?
		if ( $appCore -> _REQ( 'do') == 'resynch')
		{
			// Grab group id
			$group_id = $appCore -> _REQ( 'group');
			
			// Count group items
			$group_items = $appCore -> db -> count( 'settings', 'setting_group = \'' . $appCore -> db -> strEscape( $group_id) . '\'');
			
			// Update group
			$appCore -> db -> update( array( 'settings_group_items' => $group_items), 'settings_groups', 'settings_group_key = \'' . $appCore -> db -> strEscape( $group_id) . '\'');
			
			// Show message
			$appCore -> output -> message( $appCore -> lang['acp_settings_group_resynch'], $appCore -> lang['acp_settings_groups']);
		}
				
		// Cache output
		ob_start();
		
		// Open block that will contain list of avaiable function groups
		echo $appCore -> output -> openTableBlock( $appCore -> lang['acp_settings_groups_list']);
		
		// Select settings groups
		$appCore -> db -> query( 'SELECT *
		FROM ' . DB_PREFIX . 'settings_groups
		ORDER BY settings_group_key DESC');
		
		// Found anything?
		if ( $appCore -> db -> numRows() > 0)
		{
			// Add language string
			$appCore -> output -> js_vars['l_delete_item_sure'] =  $appCore -> lang['delete_item_sure'];
			
			// Use result
			while ( $group_result = $appCore -> db -> fetch_array())
			{
				// Draw row
				echo $appCore -> output -> tableRow( '<div class="cell left_float width_hudge">
						' . $appCore -> output -> drawImage( 'icon_settings_group') . ' <a href="' . $appCore -> adminLink( 'act=settings&settings=' . $group_result[1]) . '" class="item_title">' . $appCore -> ifString( $group_result[2]) . '</a> <span class="item_append">(' . $group_result[4] . $appCore -> lang['acp_settings_in_group'] . ')</span>' . ( isset( $group_result[3][0]) ? '<div class="item_description">' . $appCore -> ifString( $group_result[3]) . '</div>' : '') . '
					</div>
					<div class="cell left_border right_float width_small center">
						<a href="' . $appCore -> adminLink( 'act=settings_list&do=resynch&group=' . $group_result[1]) . '">' . $appCore -> output -> drawImage( 'action_refresh', $appCore -> lang['resynch']) . '</a>
						<a href="' . $appCore -> adminLink( 'act=edit_settings&do=edit&group=' . $group_result[0]) . '">' . $appCore -> output -> drawImage( 'action_edit', $appCore -> lang['edit']) . '</a>
						<a href="' . $appCore -> adminLink( 'act=edit_settings&do=delete&group=' . $group_result[0], true) . '" class="delete_confirm">' . $appCore -> output -> drawImage( 'action_delete', $appCore -> lang['delete']) . '</a>
					</div>');
			}
		}
		else
		{
			// No setting groups found
			echo $appCore -> output -> tableRow( $appCore -> lang['acp_settings_groups_not_found']);
			
		}
		
		// Close block
		echo $appCore -> output -> closeTableBlock();
				
		// Draw output
		$appCore -> output -> draw( $appCore -> lang['acp_settings_groups'], array( $appCore -> adminLink( 'act=settings_list') => $appCore -> lang['acp_settings_groups']), ob_get_clean());
				
	}
		
}